home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / TE32K.sit / TE32K Demo Folder / TE32K Documentation < prev   
Text File  |  1993-01-02  |  13KB  |  355 lines

  1.                     The TE32K TextEdit Replacement
  2.                     ==============================
  3.  
  4.                             by Roy Wood
  5.  
  6.                         122 Britannia Avenue
  7.                         London, Ontario, Canada
  8.                               N6H 2J5
  9.  
  10.                           (519) 438-3177
  11.  
  12.                  rrwood@canrem.com, rrwood@canrem.uucp
  13.  
  14.  
  15.  
  16.  
  17. Contents:
  18. =========
  19.  
  20. Introduction                 - What's this darn thing good for?
  21. Legal Stuff                    - Oh, no....
  22. Using TE32K                    - How do I use it anyway?
  23. TE32K Data Structures        - What's a TE32KRec?
  24. TE32K Interface Calls        - I have to do what?!?!?!
  25. TE32K Demo                    - Make me a believer!
  26.  
  27.  
  28.  
  29. Introduction:
  30. =============
  31.  
  32. TE32K is designed to be a more-or-less “plug in” replacement for the Macintosh Toolbox TextEdit package.  The major difference between the two editor packages is that TE32K allows for the manipulation of text-files LARGER than 32K.  There are a few other differences as well, most of which are shortcomings due to laziness on my part, but since this source code is provided to you gratis, please feel free to modify it in whatever twisted way your warped little heart desires.  If you do improve it in any way, please be kind enough to share your work with the rest of us (i.e. send me a copy so I can keep track of TE32K's current state of evolution!).
  33.  
  34. Note that TE32K is written as a non-OOP C program.  If this is not what you're interested in, I suggest you take a look at the many excellent OOP TextEdit replacement clas libraries available via FTP.
  35.  
  36. I wrote TE32K since I needed it for rnMac, a Macintosh newsreader I wrote.  Well, I didn't really need it, but it was nice to have, and I wasn't doing anything one afternoon, so.....
  37.  
  38.  
  39.  
  40. Legal Stuff:
  41. ============
  42.  
  43. TE32K is provided free of charge, since no-one will ever pay me anything for it anyway.  However, if you do use TE32K in a piece of software which you market, for every copy you sell, you are required to donate $1.00 to the World Wildlife Fund, 90 Eglinton Avenue East, Suite 504, Toronto, Ontario, Canada, M4P 2Z7.
  44.  
  45.  
  46.  
  47. Using TE32K:
  48. ============
  49.  
  50. TE32K is designed as a source-level replacement for TextEdit.  This means that you will have to compile the “TE32K.c” file along with the rest of your program.  As well, you will have to change all your TextEdit calls to the equivalent TE32K routines.  The TE32K function calls and data structures are declared in the file “TE32K.h” which you should #include in your source, too.  The data structures and interface calls are described in the following sections.
  51.  
  52.  
  53.  
  54. TE32K Data Structures:
  55. ======================
  56.  
  57. TE32K uses a couple of unconventional data stuctures to work its magic; these are defined in the “TE32K.h” header file as follows:
  58.  
  59.  
  60. /* a Rect defined with long's, rather than int's */
  61.  
  62. typedef    struct
  63. {
  64.     long        top,left,bottom,right;
  65.     
  66. } LongRect;
  67.  
  68.  
  69. /* a Point defined with long's rather than int's */
  70.  
  71. typedef    struct
  72. {
  73.     long        h,v;
  74.     
  75. } LongPoint;
  76.  
  77.  
  78. /* the TE32K data structure!  Notice the standard TextEdit field names! */
  79.  
  80. typedef pascal Boolean (*TE32KProcPtr)(void);
  81.  
  82. typedef    struct
  83. {
  84.     LongRect            destRect;    /* the destination rectangle */
  85.     LongRect            viewRect;    /* the view rectangle */
  86.     int                lineHeight;    /* height of a line of text */
  87.     int                fontAscent;    /* the font ascent */
  88.     LongPoint        selPoint;    /* the coords of the selection point */
  89.     long                selStart;    /* the start of the selected text */
  90.     long                selEnd;        /* the end of the selected text */
  91.     int                active;        /* active flag */
  92.     TE32KProcPtr        clikLoop;    /* hook for the click-loop routine */
  93.     long                clickTime;    /* time used for double-clicking */
  94.     long                clickLoc;    /* location of last click, maybe */
  95.     long                caretTime;    /* time for blinking cursor */
  96.     int                caretState;    /* state of cursor (invisible/showing) */
  97.     long                teLength;    /* size of edit text */
  98.     Handle            hText;        /* Handle to text */
  99.     int                txFont;        /* the font */
  100.     char                txFace;        /* the font face */
  101.     int                txMode;        /* the text display mode */
  102.     int                txSize;        /* the size of the text */
  103.     int                tabWidth;    /* the width of tabs */
  104.     int                crOnly;        /* do Carriage Return only? */
  105.     GrafPtr            inPort;        /* the GrafPort we're in */
  106.     long                nLines;        /* the number of lines of text */
  107.     int                theCharWidths[256];    /* quick and dirty lookup table */
  108.     long                lineStarts[];    /* the line starts array */
  109.     
  110. }     TE32KRec,*TE32KPtr,**TE32KHandle;
  111.  
  112.  
  113.  
  114. If you've done any programming with TextEdit, you'll quickly realize that these data structures are pretty easy to figure out .  Basically, I've just enlarged the relevant field sizes from int's to long's, and thrown away the fields I didn't need.  All the fields of the TE32KRec are named the same as traditional TextEdit fields, so it should be pretty simple to modify your source code to be compatible with TE32K.  The programs I've used it in were written to use TextEdit originally, but it's taken me no more than half an hour to make them compatible with TE32K.  If this seems too much effort for you, maybe you should stick with TextEdit then.
  115.  
  116. Oh— right now the crOnly field is defined such that if it is zero, word-wrapping is performed (the default set by TE32KNew), and if it is non-zero, lines are broken only at carriage returns.  Should I change this to be exactly the same as TextEdit?  Does anyone really care?
  117.     
  118.  
  119.  
  120. TE32K Interface Calls:
  121. ======================
  122.  
  123. All the public routines are described as follows, with the equivalent TextEdit routine listed below the TE32K function declaration.  The names of each routine are basically the same as the standard TextEdit routines albeit with the “TE” replaced by “TE32K”.  The parameters are pretty much the same as usual too, with the major difference being the use of long's in place of int's, etc.
  124.  
  125.  
  126. void TE32KInit(void);
  127. ---------------------
  128. replaces TEInit
  129.  
  130. Initialize the TE32K scrap Handle
  131.  
  132.  
  133. TE32KHandle TE32KNew(LongRect *destRect,LongRect *viewRect);
  134. ------------------------------------------------------------
  135. replaces TENew
  136.  
  137. Allocate and return a Handle to a new TE32K edit record, destRect and viewRect as per usual
  138.  
  139.  
  140. void     TE32KDispose(TE32KHandle theTE32KHandle);
  141. ----------------------------------------------
  142. replaces TEDispose
  143.  
  144. Dispose of a previously-allocate TE32K record
  145.  
  146.  
  147. void TE32KCalText(TE32KHandle theTE32KHandle);
  148. ----------------------------------------------
  149. TECalText
  150.  
  151. Calculate the lineStarts array for a text record
  152.  
  153.  
  154. void     TE32KSetText(Ptr theText,long length,TE32KHandle theTE32KHandle);
  155. ----------------------------------------------------------------------
  156. replaces TESetText
  157.  
  158. Set the text of the TE32K record to a copy of the text pointed at by theText, length of which is given by length parameter
  159.  
  160.  
  161. Handle TE32KGetText(TE32KHandle theTE32KHandle);
  162. ------------------------------------------------
  163. replaces TEGetText
  164.  
  165. Returns a copy of the Handle of the text record
  166.  
  167.  
  168. void TE32KUpdate(LongRect *updateRect,TE32KHandle theTE32KHandle);
  169. ------------------------------------------------------------------
  170. replaces TEUpdate
  171.  
  172. Update the display of the text within the specified update rectangle
  173.  
  174.  
  175. void TE32KScroll(long dh,long dv,TE32KHandle theTE32KHandle);
  176. -------------------------------------------------------------
  177. replaces TEScroll
  178.  
  179. Scroll the text display the amount specified by dh and dv
  180.  
  181.  
  182. void TE32KActivate(TE32KHandle theTE32KHandle);
  183. -----------------------------------------------
  184. replaces  TEActivate
  185.  
  186. Activate the text record
  187.  
  188.  
  189. void TE32KDeactivate(TE32KHandle theTE32KHandle);
  190. -------------------------------------------------
  191. replaces TEDeactivate
  192.  
  193. Deactivate the text record
  194.  
  195.  
  196. void TE32KIdle(TE32KHandle theTE32KHandle);
  197. -------------------------------------------
  198. replaces TEIdle
  199.  
  200. Call this to blink the cursor
  201.  
  202.  
  203. void TE32KKey(unsigned char theChar,TE32KHandle theTE32KHandle);
  204. ----------------------------------------------------------------
  205. replaces TEKey
  206.  
  207. Process the keystroke contained in theChar
  208.  
  209.  
  210. void TE32KClick(Point thePt,unsigned char extend,TE32KHandle theTE32KHandle);
  211. -----------------------------------------------------------------------------
  212. replaces TEClick
  213.  
  214. Respond to a mouse-down event in the view rectangle, extend indicates whether the shift-key was depressed and thus whether the user is selecting a range of text
  215.  
  216.  
  217. void TE32KSetSelect(long selStart,long selEnd,TE32KHandle theTE32KHandle);
  218. --------------------------------------------------------------------------
  219. replaces TESetSelect
  220.  
  221. Set the selection range of the text record
  222.  
  223.  
  224. void TE32KToScrap(void);
  225. ------------------------
  226. replaces TEFromScrap
  227.  
  228. Copy the TE32K scrap to the desktop/clipboard scrap
  229.  
  230.  
  231. void TE32KFromScrap(void);
  232. --------------------------
  233. replaces TEFromScrap
  234.  
  235. Copy the desktop/clipboard scrap to the TE32K scrap
  236.  
  237.  
  238. void TE32KCopy(TE32KHandle theTE32KHandle);
  239. -------------------------------------------
  240. replaces TECopy
  241.  
  242. Copy the selected range of text to the TE32K scrap
  243.  
  244.  
  245. void TE32KCut(TE32KHandle theTE32KHandle);
  246. ------------------------------------------
  247. replaces TECut
  248.  
  249. Cut the selected range of text to the TE32K scrap
  250.  
  251.  
  252. void TE32KDelete(TE32KHandle theTE32KHandle);
  253. ---------------------------------------------
  254. replaces TEDelete
  255.  
  256. Delete the selected range of text to the TE32K scrap
  257.  
  258.  
  259. void TE32KInsert(Ptr textPtr,long length,TE32KHandle theTE32KHandle);
  260. ---------------------------------------------------------------------
  261. replaces TEInsert
  262.  
  263. Insert a block of text at the current cursor location within the text record, do all necessary lineStart calculations
  264.  
  265.  
  266. void TE32KPaste(TE32KHandle theTE32KHandle);
  267. --------------------------------------------
  268. replaces TEPaste
  269.  
  270. Gee, could this be the routine to paste the TE32K scrap to the current cursor location?  I dunno....
  271.  
  272.  
  273. Handle TE32KScrapHandle(void);
  274. ------------------------------
  275. replaces TEScrapHandle
  276.  
  277. Returns a copy of the Handle to the TE32K scrap
  278.  
  279.  
  280. long TE32KGetScrapLen(void);
  281. ----------------------------
  282. replaces TEGetScrapLen
  283.  
  284. Returns the length of the TE32K scrap
  285.  
  286.  
  287. void TE32KSetScrapLen(long length);
  288. -----------------------------------
  289. replaces TESetSCrapLen
  290.  
  291. Set the length of the TE32K scrap if you've changed its length
  292.  
  293.  
  294. void TE32KGetPoint(long selIndex,LongPoint *selPt,TE32KHandle theTE32KHandle);
  295. ------------------------------------------------------------------------------
  296. replaces TEGetPoint
  297.  
  298. Returns in selPt the coordinates of the character specified by selIndex.  Right now, there's a problem with placing the cursor at the end of a wrapped line— instead, the cursor is placed at the start of the next line.  Sigh, this one is going to be messy to clear up....
  299.  
  300.  
  301. long TE32KGetOffset(LongPoint *selPt,TE32KHandle theTE32KHandle);
  302. -----------------------------------------------------------------
  303. replaces TEGetOffset
  304.  
  305. Returns the index to the character at the coordinates specified by selPt
  306.  
  307.  
  308. void TE32KSelView(TE32KHandle theTE32KHandle);
  309. ----------------------------------------------
  310. replaces TESelView
  311.  
  312. Scroll the cursor into view if it's not already visible
  313.  
  314.  
  315. void TE32KSetFontStuff(int font,int face,int mode,int size,TE32KHandle theTE32KHandle);
  316. ---------------------------------------------------------------------------------------
  317. unique to TE32K
  318.  
  319. Use to set the font, face, mode, and size of the text record and update the quick-and-dirty table of character widths used in word-wrapping calculations.  If you change the fields of the TE32KHandle on your own, things will get nasty!
  320.  
  321.  
  322. void SetLongRect(LongRect *,long,long,long,long);
  323. -------------------------------------------------
  324. unique to TE32K
  325.  
  326. Use to set the left, top, right, bottom of a LongRect; similar to SetRect
  327.  
  328.  
  329. void LongRectToRect(LongRect *,Rect *);
  330. -------------------------------------------------
  331. unique to TE32K
  332.  
  333. Convert a LongRect to a simple Rect, clipping the size if necessary
  334.  
  335.  
  336. void RectToLongRect(Rect *,LongRect *);
  337. -------------------------------------------------
  338. unique to TE32K
  339.  
  340. Convert a Rect to a LongRect
  341.  
  342.  
  343.  
  344. Phew, still with me?  Well, as promised, they're pretty much identical to their TextEdit counterparts, and modifying your source to be compatible should be a breeze, more or less.  Just watch out for the use of long's in place of int's. (And yes, I know you don't like the way I keep inflecting “long” to indicate plurality.  And I agree; it does make me look like a dummy who doesn't know anything about the possessive case, but my Canadian Writer's Handbook says that it's okay to use an apostrophe to indicate plurality for short little weird words, so I'm going to continue doing it.)
  345.  
  346.  
  347. TE32K Demo:
  348. ===========
  349.  
  350. So, you'd like to actually see TE32K in action?  Well, with the source code for TE32K, I've included a little application that allows you to open and edit text files using TE32K instead of TextEdit.  Heck, I even include the source code so you can muck around with it yourself!  It was written using Symantec's Think C, version 5.0.2 (or whatever the version number is).  I used the demo to write this document, so it sort of even works!
  351.  
  352.  
  353.  
  354. -Roy Wood, December 31, 1992.
  355.